<template>
  <div>
    <div id="slider" class="mui-slider">
      <div
        id="sliderSegmentedControl"
        class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted"
      >
        <div class="mui-scroll">
          <a
            :class="['mui-control-item',item.id==0?'mui-active':'']"
            v-for="item in cates"
            :key="item.id"
            @click="getPhotoListByCateId(item.id)"
          >{{item.title}}</a>
        </div>
      </div>
      <ul class="photo-list">
          <!-- 本身router-link是个超链接 tag 会指定渲染成什么标签， 否则下面写的css代码用li来写的 改成router-link后就会失效，所以用tag来指定标签 -->
        <router-link  v-for="item in list" :key="item.id" tag="li" :to="'/homes/photoinfo/'+item.id">
          <img v-lazy="item.img_url" />
          <div class="info">
              <h1 class="info-title">{{item.title}}</h1>
              <div class="info-body">{{item.zhaiyao}}</div>
          </div>
        </router-link>
      </ul>
    </div>
  </div>
</template>
<script>
import mui from "../../lib/mui/js/mui.js";

export default {
  data() {
    return {
      cates: [],
      list: []
    };
  },
  created() {
    this.getAllcategory();
    this.getPhotoListByCateId(0);
  },
  mounted() {
    mui(".mui-scroll-wrapper").scroll({
      deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
    });
  },
  methods: {
    getAllcategory() {
      this.$http
        .get("http://www.liulongbin.top:3005/api/getimgcategory")
        .then(function(result) {
          if (result.body.status == 0) {
            result.body.message.unshift({ title: "全部", id: 0 });
            this.cates = result.body.message;
          }
        });
    },
    getPhotoListByCateId(cateid) {
      this.$http
        .get("http://www.liulongbin.top:3005/api/getimages/" + cateid)
        .then(result => {
          if (result.body.status == 0) {
            this.list = result.body.message;
          }
        });
    }
  }
};
</script>
<style lang="less" scoped>
* {
  touch-action: pan-y;
}
.photo-list {
  margin: 0;
  padding: 10px;
  padding-bottom: 0;
  li {
      position: relative;
    background-color: #ccc;
    text-align: center;
    list-style: none;
    margin-bottom: 10px;
    box-shadow: 0 0 8px #999;
    img{
        width: 100%;
        vertical-align: middle;
    }
    img[lazy="loading"] {
      width: 40px;
      height: 300px;
      margin: auto;
      
    }
    .info{
        max-height: 84px;
        background-color:rgba(0,0,0,0.3);
        position: absolute;
        bottom: 0px;
        color: white;
        text-align: left;
        .info-title{
            font-size: 14px;
        }
        .info-body{
            font-size: 12px;
        }
    }
  }
}
</style>